<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/css/gamelist.css">
		<script src="${pageContext.request.contextPath}/js/gamelist.js"></script>
		<script>
			var flag = '${flag}'
			if (flag == '1') {
				alert('更改成功');
			} else if (flag == '2') {
				alert('更改失败');
			}
		</script>
		<div class="gamelist">
			<h1>游戏列表</h1>
			<div class="search">
				<form action="" method="post">
					<input type="text" class="text" placeholder="${query_tip}"><input type="button" value="搜索"
						class="button">
				</form>
			</div>
			<table>
				<thead>
					<tr>
						<th>序号</th>
						<th>游戏名</th>
						<th>发行商</th>
						<th>发行日期</th>
						<th>简介</th>
						<th>游戏类型</th>
						<th>管理</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${games}" var="game" varStatus="stat">
						<tr>
							<td>${stat.index+1+page}</td>
							<td>${game.gamename}</td>
							<td>${game.publisher}</td>
							<td>${game.adddate}</td>
							<td>${game.introduce}</td>
							<td>${game.type}</td>
							<td><input type="button" value="${game.state==0?'上架':'下架'}"
									onclick="javascript:window.location='change?action=change&id=${game.id}&state=${game.state}'">
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			<c:if test="${query_tip=='请输入游戏名...'}">
				<div class="page">
					<input type="button" value="首页" class="start_page">
					<input type="button" value="上一页" class="prev_page"> <input type="button" value="下一页"
						class="next_page"> <input type="button" value="尾页" class="end_page">
				</div>
				<script>
					//页面跳转
					var page = parseInt('${page}');
					var total = parseInt('${totalPage}');
					var up = $('.gamelist .page .prev_page');
					var down = $('.gamelist .page .next_page');
					var start = $('.gamelist .page .start_page');
					var end = $('.gamelist .page .end_page');
					up.click(function () {
						page = page - 8;
						if (page < 0) {
							page = 0;
						} else {
							window.location.href = 'gamelist?page=' + page;
						}
					});

					down.click(function () {
						page = page + 8;
						if (page > total * 8 - 8) {
							page = total * 8 - 8;
						} else {
							window.location.href = 'gamelist?page=' + page;
						}
					});

					start.click(function () {
						page = 0;
						window.location.href = 'gamelist?page=' + page;
					});

					end.click(function () {
						page = page = total * 8 - 8;
						window.location.href = 'gamelist?page=' + page;
					});
				</script>
			</c:if>
		</div>